package com.yz.group1.group_1.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yz.group1.group_1.entity.Schedule;
import com.yz.group1.group_1.mapper.ScheduleMapper;
import com.yz.group1.group_1.service.ScheduleService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ScheduleServiceImpl extends ServiceImpl<ScheduleMapper, Schedule> implements ScheduleService {

    private static final Logger logger = LoggerFactory.getLogger(ScheduleServiceImpl.class);

    @Override
    public List<Schedule> listAllSchedules() {
        try {
            return baseMapper.selectList(null);
        } catch (Exception e) {
            logger.error("查询所有排班信息出错", e);
            return null;
        }
    }

    // 实现个人排班查询
    @Override
    public List<Schedule> getPersonalSchedule(Integer doctorId) {
        try {
            QueryWrapper<Schedule> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("doctor_id", doctorId);
            return baseMapper.selectList(queryWrapper);
        } catch (Exception e) {
            logger.error("查询医生ID为 {} 的排班信息出错", doctorId, e);
            return null;
        }
    }
}